package handlers

import (
	"ginmt/handlers/dto"
	"ginmt/handlers/requests"
	"ginmt/handlers/response"

	"ginmt/logic"
	"ginmt/models/dao"
	"ginmt/pkg"

	"github.com/gin-gonic/gin"
)

func City(appCtx *pkg.AppCtx) func(ctx *gin.Context) {
	return func(ctx *gin.Context) {
		regionalLogic := logic.NewMtRegionalLogic(appCtx, dao.Use(appCtx.Db))
		data, err := regionalLogic.OnlyCity(ctx)
		if err != nil {
			response.Failed(ctx, response.FailedCode, err.Error())
		}
		response.Success(ctx, response.SuccessCode, dto.City(data))
	}
}

func CityValue(appCtx *pkg.AppCtx) func(ctx *gin.Context) {
	return func(ctx *gin.Context) {
		var request requests.CityValueRequest
		regionalLogic := logic.NewMtRegionalLogic(appCtx, dao.Use(appCtx.Db))
		if err := ctx.BindQuery(&request); err != nil {
			response.Failed(ctx, response.FailedCode, err.Error())
			return
		}
		cityValue, err := regionalLogic.GetValueByCity(ctx, request.City)
		if err != nil {
			response.Failed(ctx, response.FailedCode, err.Error())
			return
		}
		response.Success(ctx, response.SuccessCode, cityValue)

	}
}
